<?php
namespace app\services\yuql;

class GeoServices{

    /**
     * 获取经纬度
     * @param $address
     * @return array
     */
    public static function getLongLatByAddress($address){
        $geoUrl = sprintf(config('geo.url'),config('geo.key'),$address);
        $result = file_get_contents($geoUrl);
        $result = json_decode($result,true);
        if ($result['status'] != 1) throw new \Exception('经纬度转化失败');
        $result = $result['geocodes'][0]['location'];
        $array = explode(',',$result);
        $longitude = $array[0];
        $latitude = $array[1];
        return [$longitude,$latitude];
    }

}